package com.tbit.main.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.core.GeoreGionBoundDao;
import com.tbit.main.dao.core.GeoreGionDao;
import com.tbit.main.pojo.GeoreGion;
import com.tbit.main.pojo.GeoreGionBound;
import com.tbit.main.pojo.GeoreGionMachineCount;
import com.tbit.main.service.GeoreGionService;
import com.tbit.main.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service("georeGionService")
public class GeoreGionServiceImpl implements GeoreGionService {
    @Autowired
    private GeoreGionDao georeGionDao;
    @Autowired
    private GeoreGionBoundDao georeGionBoundDao;

    @Override
    public void insert(GeoreGion georeGion) {
        georeGionDao.insert(georeGion);
    }

    @Override
    public void update(GeoreGion georeGion) {
        georeGionDao.update(georeGion);
    }

    @Override
    public void delete(Integer regionId) {
        georeGionDao.delete(regionId);
    }

    @Override
    public GeoreGion getByRegionId(Integer regionId) {
        return georeGionDao.getByRegionId(regionId);
    }

    @Override
    public List<GeoreGion> getByRegionIds(Collection<Integer> regionIds) {
        return CollUtil.isEmpty(regionIds)
                ? Collections.emptyList()
                : georeGionDao.getByRegionIds(StringUtil.getListString(regionIds));
    }

    @Override
    public List<GeoreGion> getByAccountId(Integer accountId) {
        return georeGionDao.getByAccountId(accountId);
    }

    @Override
    public List<GeoreGion> getByAccountIds(List<Integer> accountIds) {
        return georeGionDao.getByAccountIds(StringUtil.getListString(accountIds));
    }

    @Override
    public List<GeoreGion> getAll() {
        return georeGionDao.getAll();
    }

    @Override
    public List<Integer> getAccountId() {
        return georeGionDao.getAccountId();
    }

    @Override
    public List<Integer> getAccountIdUpdate(String updateTime) {
        return georeGionDao.getAccountIdUpdate(updateTime);
    }

    @Override
    public List<Integer> getRegionId() {
        return georeGionDao.getRegionId();
    }

    @Override
    public List<Integer> getByAccountUserId(Integer accountUserId) {
        return georeGionDao.getByAccountUserId(accountUserId);
    }

    @Override
    public List<GeoreGion> getAccountUserId(Integer accountUserId) {
        return georeGionDao.getAccountUserId(accountUserId);
    }

    @Override
    public List<Map<String, Object>> getAccountUserIds(List<Integer> accountUserIds) {
        return georeGionDao.getAccountUserIds(StringUtil.getListString(accountUserIds));
    }

    @Override
    public List<Map<String, Object>> getRegionIdsUserId(List<Integer> regionId) {
        return georeGionDao.getRegionIdsUserId(StringUtil.getListString(regionId));
    }

    @Override
    public List<GeoreGionMachineCount> groupByGeoreGion(Integer accountId) {
        return georeGionDao.groupByGeoreGion(accountId);
    }

    @Override
    public void binding(GeoreGionBound georeGionBound) {
        georeGionBoundDao.binding(georeGionBound);
    }

    @Override
    public void bindingBatch(List<Map<String, Object>> map) {
        georeGionBoundDao.bindingBatch(map);
    }

    @Override
    public void unbind(GeoreGionBound georeGionBound) {
        georeGionBoundDao.unbind(georeGionBound);
    }

    @Override
    public void updateUnbind(Integer accountId, Integer regionId, Integer accountUserId, Integer isLeader) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("regionId", regionId);
        params.put("accountUserId", accountUserId);
        params.put("isLeader", isLeader);
        georeGionBoundDao.updateUnbind(params);
    }

    @Override
    public List<GeoreGionBound> getGeoreGionBound(Integer regionId, Integer accountUserId, Integer isLeader) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("regionId", regionId);
        params.put("accountUserId", accountUserId);
        params.put("isLeader", isLeader);
        return georeGionBoundDao.getGeoreGionBound(params);
    }

    @Override
    public List<GeoreGionBound> getBoundRegionIds(List<Integer> regionId) {
        return georeGionBoundDao.getBoundRegionIds(StringUtil.getListString(regionId));
    }

    @Override
    public List<Map<String, Object>> getGroupRegionId(List<Integer> regionId) {
        return georeGionBoundDao.getGroupRegionId(StringUtil.getListString(regionId));
    }

    @Override
    public Integer getMachineIdUserId(Integer accountUserId, Integer machineId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("accountUserId", accountUserId);
        params.put("machineId", machineId);
        return georeGionDao.getMachineIdUserId(params);
    }

    @Override
    public List<Map<String, Object>> getBoundAll() {
        return georeGionBoundDao.getBoundAll();
    }

    @Override
    public GeoreGion getByGeoRegionName(Integer accountId, String regionName) {
        return georeGionBoundDao.getByGeoRegionName(accountId, regionName);
    }
}